﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Web.UI;
using Baimasoft.Manage.SqlServerDAL;

public partial class SysManage_OutPage_Role_List : Baimasoft.Web.UI.PageManagerTop
{
    public static int type = 0;
    public static string sSRoleCode = "", sSRoleName = "";
    public string UserRole = "";
    public int AllCount = 0, AllPageCount = 0, NowPageCount = 0, PageSize = 0;
    DataView MyDV;

    RoleManage MyRM = new RoleManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_User_LogonID"] == null)
        {
            Response.Redirect("../ReLogon.aspx");
        }

        this.BindControlEvent();
        if (!this.IsPostBack)
        {
            GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
            this.BindGridViewData();//绑定GridView,为删除服务
        }
    }

    protected override void BindGridViewData()
    {
        this.DataSource = MyRM.SearchOutPageInfo(GetSearchString());
        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();
    }


    protected override string GetSearchString()
    {
        string searchStr = "( creator!='system' )";
        string sRoleCode = RoleCode.Text.ToString().Trim();
        if (sRoleCode != "")
        {
            searchStr += " and a.Code = '" + sRoleCode + "' ";
        }

        string sRoleName = RoleName.Text.ToString().Trim();
        if (sRoleName != "")
        {
            searchStr += " and a.Name like '%" + sRoleName + "%'";
        }

        if ((string)Session["Baimasoft_Role_Code"] != null)
        {
            searchStr += " and a.LevelCode LIKE '%#" + (string)Session["Baimasoft_Role_Code"] + "#%' ";
        }

        return searchStr;
    }


    /// <summary>
    /// 全选
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnAll_Click(object sender, EventArgs e)
    {
        HtmlInputCheckBox chk;
        string sTemp = "";
        if (hidAll.Value == "1")
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                chk = (HtmlInputCheckBox)(GridView1.Rows[i].Cells[0].FindControl("OneCheck"));
                chk.Checked = true;
                sTemp += chk.Value + "|";
            }
            ChoiceInfo.Value = ChoiceInfo.Value + sTemp;
        }
        else
        {
            string sTempNo = "";
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                chk = (HtmlInputCheckBox)(GridView1.Rows[i].Cells[0].FindControl("OneCheck"));
                chk.Checked = false;
                sTempNo += chk.Value + "|";
            }
            ChoiceInfo.Value = ChoiceInfo.Value.Replace(sTempNo, "");
        }
    }


    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnDel_Click(object sender, EventArgs e)
    {
        string sRoleCode = ChoiceInfo.Value.ToString().Trim().Replace("|", ",").TrimEnd(new char[] { ',' });
        int iback = MyRM.IFDelOutRoleInfo(sRoleCode);
        if (iback >= 1)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功!');</script>");
            this.BindGridViewData();
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败!');</script>");
        }
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnRefresh_Click(object sender, EventArgs e)
    {
        this.BindGridViewData();
    }


    protected new void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            if (e.Row.RowIndex % 2 != 0)
            {
                e.Row.Attributes.Add("onclick", "tog(this,'#EFEFF8'),GetRowInfo('" +  e.Row.Cells[1].Text + "|" + e.Row.Cells[2].Text + "|" + e.Row.Cells[3].Text + "|" + e.Row.Cells[4].Text + "|" + e.Row.Cells[5].Text + "')");
            }
            else
            {
                e.Row.Attributes.Add("onclick", "tog(this,'#F9F9FB'),GetRowInfo('" +  e.Row.Cells[1].Text + "|" + e.Row.Cells[2].Text + "|" + e.Row.Cells[3].Text + "|" + e.Row.Cells[4].Text + "|" + e.Row.Cells[5].Text + "')");
            }
        }
    }
}